/**
 * <p>Title: ServiceZMCMR0.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 高强
 * @version 1.0
 * <pre>Histroy:
 *          2011-11-22 上午09:48:39  高强  Create
 *</pre>
 */
package com.baosight.sczx.zm.cm.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;


/**
 * <p>Title: ServiceZMCMR3.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 高强
 * @version 1.0
 * <pre>Histroy:
 *          2011-11-22 上午09:48:39  高强  Create
 *</pre>
 */
public class ServiceZMCMR3 extends ServiceEPBase {
	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	/**
	 * 初始化
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCP51</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-11-22 上午09:48:39  高强
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		EiInfo outInfo = new EiInfo();
		outInfo.addBlock(getMonth("cmes.cp.month", false));//月
		outInfo.addBlock(getYear("cmes.cp.year", false));//年
		return outInfo;
	}
	
    /// <summary>
    /// 计划月份
    /// </summary>
    /// <returns></returns>
    @SuppressWarnings("rawtypes")
	public static EiBlock getMonth(String blockName, boolean isAll)
    {
    	EiBlock block = new EiBlock(blockName);

		
		EiColumn eiColumn = new EiColumn("display");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("value");
 		eiColumn.setType("C");
 		block.addMeta(eiColumn);
		
		List<Map>  _list = new ArrayList<Map>();
		Map<String, String> _map = new HashMap<String, String>();
		if(isAll) {
			_map.put("display", "");
			_map.put("value", "");
			_list.add(_map);
		}

        for (int i = 0; i < 12; i++)
        {
        	_map = new HashMap<String, String>();
			_map.put("display", i + 1 + "月");
			_map.put("value", String.valueOf(i + 1));
            _list.add(_map);
        }
        block.setRows(_list);
        return block;
    }
    
    @SuppressWarnings("rawtypes")
	public static EiBlock getYear(String blockName,boolean flag)
    {
    	EiBlock block = new EiBlock(blockName);

    	EiColumn eiColumn = new EiColumn("display");
 		eiColumn.setType("C");
 		block.addMeta(eiColumn);
 		
 		eiColumn = new EiColumn("value");
 		eiColumn.setType("C");
 		block.addMeta(eiColumn);

 		List<Map>  _list = new ArrayList<Map>();
        Map<String, String> _map = new HashMap<String, String>();
        if (flag == true)
        {
        	_map.put("display", "");
			_map.put("value", "");
            _list.add(_map);
        }

        _map = new HashMap<String, String>();
        int year =  Integer.parseInt(StaticTools.getYear()); 

		_map.put("display", String.valueOf(year - 2) + "年");
		_map.put("value", String.valueOf(year - 2));
        _list.add(_map);

        _map = new HashMap<String, String>();
        _map.put("display", String.valueOf(year - 1) + "年");
        _map.put("value", String.valueOf(year - 1));
        _list.add(_map);

        _map = new HashMap<String, String>();
        _map.put("display", String.valueOf(year)+"年");
        _map.put("value", String.valueOf(year));
        _list.add(_map);

        _map = new HashMap<String, String>();
        _map.put("display", String.valueOf(year + 1) + "年");
        _map.put("value", String.valueOf(year + 1));
        _list.add(_map);

        _map = new HashMap<String, String>();
        _map.put("display", String.valueOf(year + 2) + "年");
        _map.put("value", String.valueOf(year + 2));
        _list.add(_map);

        block.setRows(_list);
        return block;
    }
}
